﻿using ERP.Domain.Products;
using Product.API.ISerivces.Products;
using Repository.communal;

namespace Product.API.Serivces.Products
{
    /// <summary>
    /// 商品服务实现类
    /// </summary>
    public class ProductSerivce : IProductSerivces
    {
        /// <summary>
        /// 产品仓储
        /// </summary>
        private readonly IBaseRepository<ERP.Domain.Products.Product> productRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productRepository">产品仓储</param>
        public ProductSerivce(IBaseRepository<ERP.Domain.Products.Product> productRepository)
        {
            this.productRepository = productRepository;
        }

        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="product">产品表</param>
        /// <returns>返回受影响行数</returns>
        public async Task<int> AddProduct(ERP.Domain.Products.Product product)
        {
            var result = await productRepository.AddAsync(product);
            return result;
        }

        /// <summary>
        /// 删除产品（逻辑）
        /// </summary>
        /// <param name="Id">产品主键</param>
        /// <returns>返回受影响行数</returns>
        public async Task<int> DeleteProduct(int Id)
        {
            var data = await productRepository.GetModelAsync(Id);
            data.IsDelete = true;
            int result = await productRepository.Update(data);
            return result;
        }

        /// <summary>
        /// 修改产品
        /// </summary>
        /// <param name="product">产品表</param>
        /// <returns>返回受影响行数</returns>
        public async Task<int> UpdateProduct(ERP.Domain.Products.Product product)
        {
            var result = await productRepository.Update(product);
            return result;
        }


    }
}
